package com.ruoyi.boat.udp.test;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * 测试用的udp客户端
 */
public class UdpClient {

    // https://www.cnblogs.com/liyhbk/p/16451038.html

    public static void main(String[] args) throws Exception {
        // 1.定义服务器的地址、端口号、数据
        InetAddress address = InetAddress.getByName("localhost");
        // 2.定义服务器端口
        int port = 20001;

        // 3.创建发送端对象：发送端自带默认端口号
        DatagramSocket socket = new DatagramSocket(20003);

        // 4.客户端启动成功，输出提示信息
        System.out.println("****客户端启动成功****");

        // 5 发送数据出去
        byte[] buffer = "hello".getBytes();
        DatagramPacket packets = new DatagramPacket(buffer, buffer.length, address, port);
        socket.send(packets);

    }
}